package com.item.yxlottery.yxlottery.utils;

/*
 *------------------------------
 * @创建者      Administrator
 * @创建时间    2017/1/3 17:06
 * @文件描述    store排序比较器
 *------------------------------
 */

import com.item.yxlottery.yxlottery.bean.StoreBean;

import java.util.Comparator;

public class ComparatorStore implements Comparator<StoreBean> {

    private int sort;

    public ComparatorStore(int sort) {
        this.sort = sort;
    }

    @Override
    public int compare(StoreBean bean1, StoreBean bean2) {//正数:1>2;0:1=2;负数:1<2
        int flag = 0;
        if (sort == 0) {//按距离排序
            int distance1 = Integer.parseInt(bean1.getDistance());
            int distance2 = Integer.parseInt(bean2.getDistance());
            if (bean1 == bean2) {
                flag = 0;
            } else if (distance1 > distance2) {
                flag = 1;
            } else if (distance1 == distance2) {
                flag = 0;
            } else {
                flag = -1;
            }
        } else {//按销量排序
            int order1 = Integer.parseInt(bean1.getOrders());
            int order2 = Integer.parseInt(bean2.getOrders());
            if (bean1 == bean2) {
                flag = 0;
            } else if (order1 > order2) {
                flag = 1;
            } else if (order1 == order2) {
                flag = 0;
            } else {
                flag = -1;
            }
        }
        return flag;
    }
}
